<?php
uses('L10n'); 

class AppController extends Controller {

	var $helpers = array('Html', 'Form', 'Javascript');
	var $components = array('Session', 'Cookie', 'Email');

	function beforeFilter(){
		$this->_setLanguage();
		$this->pageTitle = __('Twitteverest - find famous twitterers of other users', true);
	}
	
	function _setLanguage(){		
		if($this->Cookie->read('lang') && !$this->Session->check('Config.language')){
			$this->Session->write('Config.language', $this->Cookie->read('lang'));
		}
		else if(isset($this->params['language']) && ($this->params['language'] !=  $this->Session->read('Config.language'))){
			$this->Session->write('Config.language', $this->params['language']);
			$this->Cookie->write('lang', $this->params['language'], null, '20 days');
		}
		
		$this->L10n = new L10n();
		$this->L10n->get($this->Session->read('Config.language'));
		Configure::write('Config.language', $this->Session->read('Config.language'));

	}
}
?>
